# -*- coding: utf-8 -*-

from odoo.http import request

from odoo_contrib import http as contrib_http
from odoo_contrib.parser import parse_with
from odoo_contrib.marshal import marshal_with

from ..schemas import parser
from ..schemas import marshals


@contrib_http.route('/exhibition')
class CarouselRepository(contrib_http.Controller):
    @contrib_http.route('/category/', methods=['GET'])
    @parse_with(parser.category.CategoryRepositorySchema)
    @marshal_with(marshals.category.CategoryRepositorySchema, envelope='data')
    def category_list(self):
        params = self.parser.parse()
        enabled_only = params['enabled_only']

        domains = []
        if enabled_only:
            domains.append(('enabled', '=', True))

        categories = request.env['exhibition.category'].search(
            domains,
        )
        return {
            'entries': categories,
            'count': request.env['exhibition.category'].search_count(domains),
        }
